<?php

/**
 * Created by PhpStorm.
 * User: xionggang
 * Date: 15-5-22
 * Time: 下午5:39
 */
class Type extends Admin_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model("admin/type_model");
    }

    /**
     * auto:xg
     * 栏目列表
     */
    public function index()
    {
        $data['type_arr'] = $this->type_model->getList();
        $data['op'] = 'list';
        $this->load->view('admin/type', $data);
    }

    /**
     * auto:xg
     * 修改栏目信息
     */
    public function edit()
    {
        $catid = $this->input->get('catid') ? $this->input->get('catid',true) : 0;
        if (!empty($catid)) {
            $data['info']['catid'] = $catid;
            $data['info'] = $this->type_model->getTypeinfo($catid);
        }

        $data['op'] = 'edit';
        $this->load->view('admin/type', $data);
    }

    /**
     * auto:xg
     * 保存栏目信息
     */
    public function save()
    {
        $catid = $this->input->post('catid') ? $this->input->post('catid') : 0;
        $set_date['typename'] = $this->input->post('typename');
        $set_date['typedir'] = $this->input->post('typedir');
        $set_date['title'] = $this->input->post('title');
        $set_date['keywords'] = $this->input->post('keywords');
        $set_date['description'] = $this->input->post('description');

        $return = $this->type_model->set_type_info($set_date, $catid);
        if ($return == 1) {
            cpmessage("操作成功", "/index.php?d=admin&c=type");
        } else {
            cpmessage("操作失败", "/index.php?d=admin&c=type");
        }
    }


}